package org.jsola.hr.constant;

import org.jsola.core.validator.IConst;
import org.jsola.json.JsonKit;

import java.util.HashMap;
import java.util.Map;

/**
 * 青岛社保险种类型对应编号
 *
 * @author lyh
 */
public enum QdWebSiteSocTypeIndex implements IConst {

    /**
     * 养老保险
     */
    PENSION("101","养老保险"),
    /**
     * 机关事业养老
     */
    PENSION_ORGAN("102","机关事业养老"),
    /**
     * 职业年金
     */
    OCCUPATIONAL_PENSION("108","职业年金"),
    /**
     * 失业保险
     */
    UNEMPLOYMENT("201","失业保险"),
    /**
     * 工伤保险
     */
    INDUCTRIAL_INJURY("401","工伤保险"),
    /**
     * 医疗保险
     */
    HEALTH_INSURANCE("301","医疗保险"),
    /**
     * 生育保险
     */
    MATERNITY_INSURANCE("501","生育保险");

    private final String value;
    private final String desc;
    /**
     * 枚举值罗列，给swagger接口文档展示用
     */
    public static final String VALUES_STR = "101,102,108,201,401,301,501";

     /**
     * 缓存所有value
     */
    private static final Map<String, QdWebSiteSocTypeIndex> LOOKUP = new HashMap<>();

    static {
        for (QdWebSiteSocTypeIndex e : QdWebSiteSocTypeIndex.values()) {
            LOOKUP.put(e.value, e);
        }
    }


    QdWebSiteSocTypeIndex(String value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    /**
     * 根据value查找QdWebSiteSocTypeIndex
     * @param value value
     * @return QdWebSiteSocTypeIndex
     */
    public static QdWebSiteSocTypeIndex find(String value) {
        return LOOKUP.get(value);
    }

    /**
     * 根据desc查找QdWebSiteSocTypeIndex
     * @param desc desc
     * @return QdWebSiteSocTypeIndex
     */
    public static QdWebSiteSocTypeIndex findByDesc(String desc){
        for (QdWebSiteSocTypeIndex e : QdWebSiteSocTypeIndex.values()) {
            if(e.getDesc().equals(desc)){
                return e;
            }
        }
        return null;
    }

    /**
     * 所有枚举转json
     * @return json
     */
    public static String getAllToJson() {
        Map<String,Object> map = new HashMap<>();
        for (QdWebSiteSocTypeIndex e : QdWebSiteSocTypeIndex.values()) {
            map.put("value", e.value);
            map.put("desc", e.desc);
        }
        return JsonKit.toJSONString(map);
    }

    @Override
    public boolean check(Object obj) {
        String value = (String) obj;
        return find(value) != null;
    }

    public String getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
}
